package c.e.a.b.f.b;

import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ServiceInfo;
import android.content.pm.Signature;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import b.i.b.f;
import c.e.a.b.b.e;
import c.e.a.b.b.j.c;
import c.e.a.b.b.j.d;
import c.e.a.b.b.k.b;
import c.e.a.b.e.c.fa;
import c.e.a.b.e.c.hc;
import c.e.a.b.e.c.i8;
import c.e.a.b.e.c.j8;
import com.google.android.gms.measurement.internal.zzap;
import com.google.android.gms.measurement.internal.zzaq;
import com.google.android.gms.measurement.internal.zzku;
import com.google.android.gms.measurement.internal.zzz;
import com.huawei.hms.jos.games.player.GameTrialConstant;
import com.huawei.hms.jos.games.ranking.RankingConst;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.io.ByteArrayInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicLong;
import javax.security.auth.x500.X500Principal;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final class t9 extends r5 {
    public static final String[] g = new String[]{"firebase_", "google_", "ga_"};
    public static final String[] h = new String[]{"_err"};
    public SecureRandom c;
    public final AtomicLong d = new AtomicLong(0);
    public int e;
    public Integer f = null;

    public t9(u4 u4Var) {
        super(u4Var);
    }

    public static Bundle A(List<zzku> list) {
        Bundle bundle = new Bundle();
        if (list == null) {
            return bundle;
        }
        for (zzku zzku : list) {
            String str = zzku.e;
            if (str != null) {
                bundle.putString(zzku.b, str);
            } else {
                Long l = zzku.d;
                if (l != null) {
                    bundle.putLong(zzku.b, l.longValue());
                } else {
                    Double d = zzku.g;
                    if (d != null) {
                        bundle.putDouble(zzku.b, d.doubleValue());
                    }
                }
            }
        }
        return bundle;
    }

    public static String E(String str, int i, boolean z) {
        if (str == null) {
            return null;
        }
        if (str.codePointCount(0, str.length()) <= i) {
            return str;
        }
        if (z) {
            return String.valueOf(str.substring(0, str.offsetByCodePoints(0, i))).concat("...");
        }
        return null;
    }

    public static void F(Bundle bundle, int i, String str, Object obj) {
        if (l0(bundle, i)) {
            bundle.putString("_ev", E(str, 40, true));
            if (obj == null) {
                return;
            }
            if ((obj instanceof String) || (obj instanceof CharSequence)) {
                bundle.putLong("_el", (long) String.valueOf(obj).length());
            }
        }
    }

    public static boolean U(Context context) {
        Objects.requireNonNull(context, "null reference");
        if (VERSION.SDK_INT >= 24) {
            return k0(context, "com.google.android.gms.measurement.AppMeasurementJobService");
        }
        return k0(context, "com.google.android.gms.measurement.AppMeasurementService");
    }

    public static boolean V(Intent intent) {
        String stringExtra = intent.getStringExtra("android.intent.extra.REFERRER_NAME");
        return "android-app://com.google.android.googlequicksearchbox/https/www.google.com".equals(stringExtra) || "https://www.google.com".equals(stringExtra) || "android-app://com.google.appcrawler".equals(stringExtra);
    }

    public static boolean W(Object obj) {
        return (obj instanceof Parcelable[]) || (obj instanceof ArrayList) || (obj instanceof Bundle);
    }

    public static boolean X(String str) {
        f.N(str);
        if (str.charAt(0) != '_' || str.equals("_ep")) {
            return true;
        }
        return false;
    }

    public static boolean d0(String str, String str2, String str3, String str4) {
        boolean isEmpty = TextUtils.isEmpty(str);
        boolean isEmpty2 = TextUtils.isEmpty(str2);
        if (!isEmpty && !isEmpty2) {
            return !str.equals(str2);
        } else {
            if (isEmpty && isEmpty2) {
                return (TextUtils.isEmpty(str3) || TextUtils.isEmpty(str4)) ? !TextUtils.isEmpty(str4) : !str3.equals(str4);
            } else {
                if (isEmpty || !isEmpty2) {
                    return TextUtils.isEmpty(str3) || !str3.equals(str4);
                } else {
                    if (TextUtils.isEmpty(str4)) {
                        return false;
                    }
                    return TextUtils.isEmpty(str3) || !str3.equals(str4);
                }
            }
        }
    }

    public static boolean e0(String str, String[] strArr) {
        for (String q0 : strArr) {
            if (q0(str, q0)) {
                return true;
            }
        }
        return false;
    }

    public static byte[] g0(Parcelable parcelable) {
        if (parcelable == null) {
            return null;
        }
        Parcel obtain = Parcel.obtain();
        try {
            parcelable.writeToParcel(obtain, 0);
            byte[] marshall = obtain.marshall();
            return marshall;
        } finally {
            obtain.recycle();
        }
    }

    public static ArrayList<Bundle> j0(List<zzz> list) {
        if (list == null) {
            return new ArrayList(0);
        }
        ArrayList arrayList = new ArrayList(list.size());
        for (zzz zzz : list) {
            zzap zzap;
            Bundle bundle = new Bundle();
            bundle.putString(HiAnalyticsConstant.BI_KEY_APP_ID, zzz.a);
            bundle.putString("origin", zzz.b);
            bundle.putLong("creation_timestamp", zzz.d);
            bundle.putString(RankingConst.RANKING_JGW_NAME, zzz.c.b);
            d.C(bundle, zzz.c.b());
            bundle.putBoolean("active", zzz.e);
            String str = zzz.f;
            if (str != null) {
                bundle.putString("trigger_event_name", str);
            }
            zzaq zzaq = zzz.g;
            if (zzaq != null) {
                bundle.putString("timed_out_event_name", zzaq.a);
                zzap = zzz.g.b;
                if (zzap != null) {
                    bundle.putBundle("timed_out_event_params", zzap.c());
                }
            }
            bundle.putLong("trigger_timeout", zzz.h);
            zzaq = zzz.i;
            if (zzaq != null) {
                bundle.putString("triggered_event_name", zzaq.a);
                zzap = zzz.i.b;
                if (zzap != null) {
                    bundle.putBundle("triggered_event_params", zzap.c());
                }
            }
            bundle.putLong("triggered_timestamp", zzz.c.c);
            bundle.putLong("time_to_live", zzz.j);
            zzaq = zzz.k;
            if (zzaq != null) {
                bundle.putString("expired_event_name", zzaq.a);
                zzap zzap2 = zzz.k.b;
                if (zzap2 != null) {
                    bundle.putBundle("expired_event_params", zzap2.c());
                }
            }
            arrayList.add(bundle);
        }
        return arrayList;
    }

    public static boolean k0(Context context, String str) {
        try {
            PackageManager packageManager = context.getPackageManager();
            if (packageManager == null) {
                return false;
            }
            ServiceInfo serviceInfo = packageManager.getServiceInfo(new ComponentName(context, str), 0);
            if (serviceInfo != null && serviceInfo.enabled) {
                return true;
            }
            return false;
        } catch (NameNotFoundException unused) {
        }
    }

    public static boolean l0(Bundle bundle, int i) {
        if (bundle == null) {
            return false;
        }
        String str = "_err";
        if (bundle.getLong(str) != 0) {
            return false;
        }
        bundle.putLong(str, (long) i);
        return true;
    }

    public static boolean q0(String str, String str2) {
        if (str == null && str2 == null) {
            return true;
        }
        return str == null ? false : str.equals(str2);
    }

    public static boolean r0(String str) {
        return !TextUtils.isEmpty(str) && str.startsWith("_");
    }

    public static long u(long j, long j2) {
        return ((j2 * 60000) + j) / 86400000;
    }

    public static long v(zzap zzap) {
        long j = 0;
        if (zzap == null) {
            return 0;
        }
        for (String b : zzap.a.keySet()) {
            Object b2 = zzap.b(b);
            if (b2 instanceof Parcelable[]) {
                j += (long) ((Parcelable[]) b2).length;
            }
        }
        return j;
    }

    public static long w(byte[] bArr) {
        Objects.requireNonNull(bArr, "null reference");
        long j = null;
        if ((bArr.length > 0 ? 1 : null) != null) {
            long j2 = 0;
            int length = bArr.length - 1;
            while (length >= 0 && length >= bArr.length - 8) {
                j2 += (((long) bArr[length]) & 255) << j;
                j += 8;
                length--;
            }
            return j2;
        }
        throw new IllegalStateException();
    }

    public static MessageDigest x0() {
        int i = 0;
        while (i < 2) {
            try {
                MessageDigest instance = MessageDigest.getInstance("MD5");
                if (instance != null) {
                    return instance;
                }
                i++;
            } catch (NoSuchAlgorithmException unused) {
            }
        }
        return null;
    }

    public final zzaq B(String str, String str2, Bundle bundle, String str3, long j, boolean z, boolean z2) {
        if (TextUtils.isEmpty(str2)) {
            return null;
        }
        if (t(str2, z2) == 0) {
            Bundle bundle2;
            if (bundle != null) {
                bundle2 = new Bundle(bundle);
            } else {
                bundle2 = new Bundle();
            }
            String str4 = "_o";
            bundle2.putString(str4, str3);
            Bundle z3 = z(str, str2, bundle2, Collections.singletonList(str4), false);
            if (z) {
                z3 = y(z3);
            }
            return new zzaq(str2, new zzap(z3), str3, j);
        }
        d().f.b("Invalid conditional property event name", j().y(str2));
        throw new IllegalArgumentException();
    }

    public final Object C(int i, Object obj, boolean z, boolean z2) {
        if (obj == null) {
            return null;
        }
        if ((obj instanceof Long) || (obj instanceof Double)) {
            return obj;
        }
        if (obj instanceof Integer) {
            return Long.valueOf((long) ((Integer) obj).intValue());
        }
        if (obj instanceof Byte) {
            return Long.valueOf((long) ((Byte) obj).byteValue());
        }
        if (obj instanceof Short) {
            return Long.valueOf((long) ((Short) obj).shortValue());
        }
        if (obj instanceof Boolean) {
            return Long.valueOf(((Boolean) obj).booleanValue() ? 1 : 0);
        } else if (obj instanceof Float) {
            return Double.valueOf(((Float) obj).doubleValue());
        } else {
            if ((obj instanceof String) || (obj instanceof Character) || (obj instanceof CharSequence)) {
                return E(String.valueOf(obj), i, z);
            }
            if (!z2 || (!(obj instanceof Bundle[]) && !(obj instanceof Parcelable[]))) {
                return null;
            }
            ArrayList arrayList = new ArrayList();
            for (Parcelable parcelable : (Parcelable[]) obj) {
                if (parcelable instanceof Bundle) {
                    Bundle y = y((Bundle) parcelable);
                    if (!y.isEmpty()) {
                        arrayList.add(y);
                    }
                }
            }
            return arrayList.toArray(new Bundle[arrayList.size()]);
        }
    }

    public final Object D(String str, Object obj) {
        int i = 256;
        if ("_ev".equals(str)) {
            return C(256, obj, true, true);
        }
        if (!r0(str)) {
            i = 100;
        }
        return C(i, obj, false, true);
    }

    public final void G(Bundle bundle, long j) {
        String str = "_et";
        long j2 = bundle.getLong(str);
        if (j2 != 0) {
            d().i.b("Params already contained engagement", Long.valueOf(j2));
        }
        bundle.putLong(str, j + j2);
    }

    public final void H(Bundle bundle, Bundle bundle2) {
        if (bundle2 != null) {
            for (String str : bundle2.keySet()) {
                if (!bundle.containsKey(str)) {
                    k().I(bundle, str, bundle2.get(str));
                }
            }
        }
    }

    public final void I(Bundle bundle, String str, Object obj) {
        if (bundle != null) {
            if (obj instanceof Long) {
                bundle.putLong(str, ((Long) obj).longValue());
            } else if (obj instanceof String) {
                bundle.putString(str, String.valueOf(obj));
            } else if (obj instanceof Double) {
                bundle.putDouble(str, ((Double) obj).doubleValue());
            } else if (obj instanceof Bundle[]) {
                bundle.putParcelableArray(str, (Bundle[]) obj);
            } else {
                if (str != null) {
                    d().k.c("Not putting event parameter. Invalid value type. name, type", j().x(str), obj != null ? obj.getClass().getSimpleName() : null);
                }
            }
        }
    }

    public final void J(hc hcVar, int i) {
        Bundle bundle = new Bundle();
        bundle.putInt("r", i);
        try {
            hcVar.p(bundle);
        } catch (RemoteException e) {
            this.a.d().i.b("Error returning int value to wrapper", e);
        }
    }

    public final void K(hc hcVar, long j) {
        Bundle bundle = new Bundle();
        bundle.putLong("r", j);
        try {
            hcVar.p(bundle);
        } catch (RemoteException e) {
            this.a.d().i.b("Error returning long value to wrapper", e);
        }
    }

    public final void L(hc hcVar, Bundle bundle) {
        try {
            hcVar.p(bundle);
        } catch (RemoteException e) {
            this.a.d().i.b("Error returning bundle value to wrapper", e);
        }
    }

    public final void M(hc hcVar, String str) {
        Bundle bundle = new Bundle();
        bundle.putString("r", str);
        try {
            hcVar.p(bundle);
        } catch (RemoteException e) {
            this.a.d().i.b("Error returning string value to wrapper", e);
        }
    }

    public final void N(hc hcVar, ArrayList<Bundle> arrayList) {
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList("r", arrayList);
        try {
            hcVar.p(bundle);
        } catch (RemoteException e) {
            this.a.d().i.b("Error returning bundle list to wrapper", e);
        }
    }

    public final void O(hc hcVar, boolean z) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("r", z);
        try {
            hcVar.p(bundle);
        } catch (RemoteException e) {
            this.a.d().i.b("Error returning boolean value to wrapper", e);
        }
    }

    public final void P(hc hcVar, byte[] bArr) {
        Bundle bundle = new Bundle();
        bundle.putByteArray("r", bArr);
        try {
            hcVar.p(bundle);
        } catch (RemoteException e) {
            this.a.d().i.b("Error returning byte array to wrapper", e);
        }
    }

    public final void Q(u3 u3Var, int i) {
        Iterator it = new TreeSet(u3Var.d.keySet()).iterator();
        int i2 = 0;
        while (it.hasNext()) {
            String str = (String) it.next();
            if (X(str)) {
                i2++;
                if (i2 > i) {
                    StringBuilder stringBuilder = new StringBuilder(48);
                    stringBuilder.append("Event can't contain more than ");
                    stringBuilder.append(i);
                    stringBuilder.append(" params");
                    d().h.c(stringBuilder.toString(), j().u(u3Var.a), j().s(u3Var.d));
                    l0(u3Var.d, 5);
                    u3Var.d.remove(str);
                }
            }
        }
    }

    public final void R(v9 v9Var, int i, String str, String str2, int i2) {
        S(v9Var, null, i, str, str2, i2);
    }

    public final void S(v9 v9Var, String str, int i, String str2, String str3, int i2) {
        Bundle bundle = new Bundle();
        l0(bundle, i);
        if (!(TextUtils.isEmpty(str2) || TextUtils.isEmpty(str3))) {
            bundle.putString(str2, str3);
        }
        if (i == 6 || i == 7 || i == 2) {
            bundle.putLong("_el", (long) i2);
        }
        if (((i8) j8.b.q()).q() && this.a.g.o(p.O0)) {
            v9Var.a(str, bundle);
        } else {
            this.a.s().H("auto", "_err", bundle);
        }
    }

    public final void T(String str, String str2, String str3, Bundle bundle, List<String> list, boolean z) {
        String str4 = str2;
        Bundle bundle2 = bundle;
        List<String> list2 = list;
        if (bundle2 != null) {
            Iterator it = new TreeSet(bundle.keySet()).iterator();
            int i = 0;
            while (it.hasNext()) {
                int u0;
                String str5 = (String) it.next();
                if (list2 == null || !list2.contains(str5)) {
                    u0 = z ? u0(str5) : 0;
                    if (u0 == 0) {
                        u0 = w0(str5);
                    }
                } else {
                    u0 = 0;
                }
                if (u0 != 0) {
                    F(bundle2, u0, str5, u0 == 3 ? str5 : null);
                    bundle2.remove(str5);
                } else {
                    String str6;
                    if (W(bundle2.get(str5))) {
                        d().k.d("Nested Bundle parameters are not allowed; discarded. event name, param name, child param name", str4, str3, str5);
                        u0 = 22;
                        str6 = str5;
                    } else {
                        String str7 = str3;
                        str6 = str5;
                        u0 = s(str, str2, str5, bundle2.get(str5), bundle, list, z, false);
                    }
                    if (u0 != 0 && !"_ev".equals(str6)) {
                        F(bundle2, u0, str6, bundle2.get(str6));
                        bundle2.remove(str6);
                    } else if (X(str6) && !e0(str6, u5.d)) {
                        i++;
                        if (i > 0) {
                            d().h.c("Item cannot contain custom parameters", j().u(str4), j().s(bundle2));
                            l0(bundle2, 23);
                            bundle2.remove(str6);
                        }
                    }
                }
            }
        }
    }

    @SuppressLint({"ApplySharedPref"})
    public final boolean Y(String str, double d) {
        try {
            Editor edit = this.a.a.getSharedPreferences("google.analytics.deferred.deeplink.prefs", 0).edit();
            edit.putString("deeplink", str);
            edit.putLong("timestamp", Double.doubleToRawLongBits(d));
            return edit.commit();
        } catch (Exception e) {
            d().f.b("Failed to persist Deferred Deep Link. exception", e);
            return false;
        }
    }

    public final boolean Z(String str, int i, String str2) {
        if (str2 == null) {
            d().h.b("Name is required and can't be null. Type", str);
            return false;
        } else if (str2.codePointCount(0, str2.length()) <= i) {
            return true;
        } else {
            d().h.d("Name is too long. Type, maximum supported length, name", str, Integer.valueOf(i), str2);
            return false;
        }
    }

    public final boolean a0(String str, String str2) {
        if (str2 == null) {
            d().h.b("Name is required and can't be null. Type", str);
            return false;
        } else if (str2.length() == 0) {
            d().h.b("Name is required and can't be empty. Type", str);
            return false;
        } else {
            int codePointAt = str2.codePointAt(0);
            if (Character.isLetter(codePointAt)) {
                int length = str2.length();
                codePointAt = Character.charCount(codePointAt);
                while (codePointAt < length) {
                    int codePointAt2 = str2.codePointAt(codePointAt);
                    if (codePointAt2 == 95 || Character.isLetterOrDigit(codePointAt2)) {
                        codePointAt += Character.charCount(codePointAt2);
                    } else {
                        d().h.c("Name must consist of letters, digits or _ (underscores). Type, name", str, str2);
                        return false;
                    }
                }
                return true;
            }
            d().h.c("Name must start with a letter. Type, name", str, str2);
            return false;
        }
    }

    public final boolean b0(String str, String str2, int i, Object obj) {
        if (!(obj == null || (obj instanceof Long) || (obj instanceof Float) || (obj instanceof Integer) || (obj instanceof Byte) || (obj instanceof Short) || (obj instanceof Boolean) || (obj instanceof Double))) {
            if (!(obj instanceof String) && !(obj instanceof Character) && !(obj instanceof CharSequence)) {
                return false;
            }
            String valueOf = String.valueOf(obj);
            if (valueOf.codePointCount(0, valueOf.length()) > i) {
                d().k.d("Value is too long; discarded. Value kind, name, value length", str, str2, Integer.valueOf(valueOf.length()));
                return false;
            }
        }
        return true;
    }

    public final boolean c0(String str, String str2, String str3) {
        String str4 = "^(1:\\d+:android:[a-f0-9]+|ca-app-pub-.*)$";
        String str5 = "null reference";
        if (!TextUtils.isEmpty(str)) {
            Objects.requireNonNull(str, str5);
            if (!str.matches(str4)) {
                if (this.a.v()) {
                    d().h.b("Invalid google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI. provided id", q3.s(str));
                }
                return false;
            }
        } else if (!(fa.a() && this.a.g.o(p.j0) && !TextUtils.isEmpty(str3))) {
            if (TextUtils.isEmpty(str2)) {
                if (this.a.v()) {
                    d().h.a("Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI");
                }
                return false;
            }
            Objects.requireNonNull(str2, str5);
            if (!str2.matches(str4)) {
                d().h.b("Invalid admob_app_id. Analytics disabled.", q3.s(str2));
                return false;
            }
        }
        return true;
    }

    public final boolean f0(String str, String[] strArr, String[] strArr2, String str2) {
        if (str2 == null) {
            d().h.b("Name is required and can't be null. Type", str);
            return false;
        }
        Object obj;
        for (String startsWith : g) {
            if (str2.startsWith(startsWith)) {
                obj = 1;
                break;
            }
        }
        obj = null;
        if (obj != null) {
            d().h.c("Name starts with reserved prefix. Type, name", str, str2);
            return false;
        } else if (strArr == null || !e0(str2, strArr) || (strArr2 != null && e0(str2, strArr2))) {
            return true;
        } else {
            d().h.c("Name is reserved. Type, name", str, str2);
            return false;
        }
    }

    public final int h0(String str) {
        String str2 = "user property";
        if (!m0(str2, str)) {
            return 6;
        }
        if (!f0(str2, x5.a, null, str)) {
            return 15;
        }
        if (Z(str2, 24, str)) {
            return 0;
        }
        return 6;
    }

    public final int i0(String str, Object obj) {
        boolean b0;
        if ("_ldl".equals(str)) {
            b0 = b0("user property referrer", str, z0(str), obj);
        } else {
            b0 = b0("user property", str, z0(str), obj);
        }
        return b0 ? 0 : 7;
    }

    public final void m() {
        g();
        SecureRandom secureRandom = new SecureRandom();
        long nextLong = secureRandom.nextLong();
        if (nextLong == 0) {
            nextLong = secureRandom.nextLong();
            if (nextLong == 0) {
                d().i.a("Utils falling back to Random for random id");
            }
        }
        this.d.set(nextLong);
    }

    public final boolean m0(String str, String str2) {
        if (str2 == null) {
            d().h.b("Name is required and can't be null. Type", str);
            return false;
        } else if (str2.length() == 0) {
            d().h.b("Name is required and can't be empty. Type", str);
            return false;
        } else {
            int codePointAt = str2.codePointAt(0);
            if (Character.isLetter(codePointAt) || codePointAt == 95) {
                int length = str2.length();
                codePointAt = Character.charCount(codePointAt);
                while (codePointAt < length) {
                    int codePointAt2 = str2.codePointAt(codePointAt);
                    if (codePointAt2 == 95 || Character.isLetterOrDigit(codePointAt2)) {
                        codePointAt += Character.charCount(codePointAt2);
                    } else {
                        d().h.c("Name must consist of letters, digits or _ (underscores). Type, name", str, str2);
                        return false;
                    }
                }
                return true;
            }
            d().h.c("Name must start with a letter or _ (underscore). Type, name", str, str2);
            return false;
        }
    }

    public final Object n0(String str, Object obj) {
        if ("_ldl".equals(str)) {
            return C(z0(str), obj, true, false);
        }
        return C(z0(str), obj, false, false);
    }

    public final boolean o0(Context context, String str) {
        X500Principal x500Principal = new X500Principal("CN=Android Debug,O=Android,C=US");
        try {
            PackageInfo packageInfo = b.a(context).a.getPackageManager().getPackageInfo(str, 64);
            if (packageInfo != null) {
                Signature[] signatureArr = packageInfo.signatures;
                if (signatureArr != null && signatureArr.length > 0) {
                    return ((X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(signatureArr[0].toByteArray()))).getSubjectX500Principal().equals(x500Principal);
                }
            }
        } catch (CertificateException e) {
            d().f.b("Error obtaining certificate", e);
        } catch (NameNotFoundException e2) {
            d().f.b("Package name not found", e2);
        }
        return true;
    }

    public final boolean p0(String str) {
        g();
        if (b.a(this.a.a).a.checkCallingOrSelfPermission(str) == 0) {
            return true;
        }
        d().m.b("Permission not granted", str);
        return false;
    }

    public final boolean r() {
        return true;
    }

    /* JADX WARNING: Removed duplicated region for block: B:26:0x0076  */
    /* JADX WARNING: Removed duplicated region for block: B:26:0x0076  */
    /* JADX WARNING: Removed duplicated region for block: B:50:0x00d0  */
    /* JADX WARNING: Removed duplicated region for block: B:49:0x00cf A:{RETURN} */
    public final int s(java.lang.String r17, java.lang.String r18, java.lang.String r19, java.lang.Object r20, android.os.Bundle r21, java.util.List<java.lang.String> r22, boolean r23, boolean r24) {
        /*
        r16 = this;
        r7 = r16;
        r8 = r19;
        r0 = r20;
        r1 = r21;
        r16.g();
        r2 = W(r20);
        r9 = 1;
        r10 = 0;
        r3 = "param";
        if (r2 == 0) goto L_0x00a9;
    L_0x0015:
        if (r24 == 0) goto L_0x00a6;
    L_0x0017:
        r2 = c.e.a.b.f.b.u5.c;
        r2 = e0(r8, r2);
        if (r2 != 0) goto L_0x0022;
    L_0x001f:
        r0 = 20;
        return r0;
    L_0x0022:
        r2 = r7.a;
        r2 = r2.x();
        r2.g();
        r2.t();
        r4 = r2.G();
        if (r4 != 0) goto L_0x0035;
    L_0x0034:
        goto L_0x0042;
    L_0x0035:
        r2 = r2.k();
        r2 = r2.y0();
        r4 = 200900; // 0x310c4 float:2.81521E-40 double:9.9258E-319;
        if (r2 < r4) goto L_0x0044;
    L_0x0042:
        r2 = 1;
        goto L_0x0045;
    L_0x0044:
        r2 = 0;
    L_0x0045:
        if (r2 != 0) goto L_0x004a;
    L_0x0047:
        r0 = 25;
        return r0;
    L_0x004a:
        r2 = r0 instanceof android.os.Parcelable[];
        r4 = 200; // 0xc8 float:2.8E-43 double:9.9E-322;
        if (r2 == 0) goto L_0x0055;
    L_0x0050:
        r5 = r0;
        r5 = (android.os.Parcelable[]) r5;
        r5 = r5.length;
        goto L_0x0060;
    L_0x0055:
        r5 = r0 instanceof java.util.ArrayList;
        if (r5 == 0) goto L_0x0073;
    L_0x0059:
        r5 = r0;
        r5 = (java.util.ArrayList) r5;
        r5 = r5.size();
    L_0x0060:
        if (r5 <= r4) goto L_0x0073;
    L_0x0062:
        r6 = r16.d();
        r6 = r6.k;
        r5 = java.lang.Integer.valueOf(r5);
        r11 = "Parameter array is too long; discarded. Value kind, name, array length";
        r6.d(r11, r3, r8, r5);
        r5 = 0;
        goto L_0x0074;
    L_0x0073:
        r5 = 1;
    L_0x0074:
        if (r5 != 0) goto L_0x00a9;
    L_0x0076:
        if (r2 == 0) goto L_0x0088;
    L_0x0078:
        r2 = r0;
        r2 = (android.os.Parcelable[]) r2;
        r5 = r2.length;
        if (r5 <= r4) goto L_0x00a1;
    L_0x007e:
        r2 = java.util.Arrays.copyOf(r2, r4);
        r2 = (android.os.Parcelable[]) r2;
        r1.putParcelableArray(r8, r2);
        goto L_0x00a1;
    L_0x0088:
        r2 = r0 instanceof java.util.ArrayList;
        if (r2 == 0) goto L_0x00a1;
    L_0x008c:
        r2 = r0;
        r2 = (java.util.ArrayList) r2;
        r5 = r2.size();
        if (r5 <= r4) goto L_0x00a1;
    L_0x0095:
        r5 = new java.util.ArrayList;
        r2 = r2.subList(r10, r4);
        r5.<init>(r2);
        r1.putParcelableArrayList(r8, r5);
    L_0x00a1:
        r1 = 17;
        r11 = 17;
        goto L_0x00aa;
    L_0x00a6:
        r0 = 21;
        return r0;
    L_0x00a9:
        r11 = 0;
    L_0x00aa:
        r1 = r7.a;
        r1 = r1.g;
        r2 = c.e.a.b.f.b.p.R;
        r12 = r17;
        r1 = r1.u(r12, r2);
        if (r1 == 0) goto L_0x00be;
    L_0x00b8:
        r1 = r0(r18);
        if (r1 != 0) goto L_0x00c4;
    L_0x00be:
        r1 = r0(r19);
        if (r1 == 0) goto L_0x00c7;
    L_0x00c4:
        r1 = 256; // 0x100 float:3.59E-43 double:1.265E-321;
        goto L_0x00c9;
    L_0x00c7:
        r1 = 100;
    L_0x00c9:
        r1 = r7.b0(r3, r8, r1, r0);
        if (r1 == 0) goto L_0x00d0;
    L_0x00cf:
        return r11;
    L_0x00d0:
        if (r24 == 0) goto L_0x0160;
    L_0x00d2:
        r1 = r0 instanceof android.os.Bundle;
        if (r1 == 0) goto L_0x00ea;
    L_0x00d6:
        r4 = r0;
        r4 = (android.os.Bundle) r4;
        r0 = r16;
        r1 = r17;
        r2 = r18;
        r3 = r19;
        r5 = r22;
        r6 = r23;
        r0.T(r1, r2, r3, r4, r5, r6);
        goto L_0x015d;
    L_0x00ea:
        r1 = r0 instanceof android.os.Parcelable[];
        if (r1 == 0) goto L_0x0120;
    L_0x00ee:
        r13 = r0;
        r13 = (android.os.Parcelable[]) r13;
        r14 = r13.length;
        r15 = 0;
    L_0x00f3:
        if (r15 >= r14) goto L_0x015d;
    L_0x00f5:
        r0 = r13[r15];
        r1 = r0 instanceof android.os.Bundle;
        if (r1 != 0) goto L_0x010b;
    L_0x00fb:
        r1 = r16.d();
        r1 = r1.k;
        r0 = r0.getClass();
        r2 = "All Parcelable[] elements must be of type Bundle. Value type, name";
        r1.c(r2, r0, r8);
        goto L_0x015c;
    L_0x010b:
        r4 = r0;
        r4 = (android.os.Bundle) r4;
        r0 = r16;
        r1 = r17;
        r2 = r18;
        r3 = r19;
        r5 = r22;
        r6 = r23;
        r0.T(r1, r2, r3, r4, r5, r6);
        r15 = r15 + 1;
        goto L_0x00f3;
    L_0x0120:
        r1 = r0 instanceof java.util.ArrayList;
        if (r1 == 0) goto L_0x015c;
    L_0x0124:
        r13 = r0;
        r13 = (java.util.ArrayList) r13;
        r14 = r13.size();
        r0 = 0;
    L_0x012c:
        if (r0 >= r14) goto L_0x015d;
    L_0x012e:
        r1 = r13.get(r0);
        r15 = r0 + 1;
        r0 = r1 instanceof android.os.Bundle;
        if (r0 != 0) goto L_0x0148;
    L_0x0138:
        r0 = r16.d();
        r0 = r0.k;
        r1 = r1.getClass();
        r2 = "All ArrayList elements must be of type Bundle. Value type, name";
        r0.c(r2, r1, r8);
        goto L_0x015c;
    L_0x0148:
        r4 = r1;
        r4 = (android.os.Bundle) r4;
        r0 = r16;
        r1 = r17;
        r2 = r18;
        r3 = r19;
        r5 = r22;
        r6 = r23;
        r0.T(r1, r2, r3, r4, r5, r6);
        r0 = r15;
        goto L_0x012c;
    L_0x015c:
        r9 = 0;
    L_0x015d:
        if (r9 == 0) goto L_0x0160;
    L_0x015f:
        return r11;
    L_0x0160:
        r0 = 4;
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.b.f.b.t9.s(java.lang.String, java.lang.String, java.lang.String, java.lang.Object, android.os.Bundle, java.util.List, boolean, boolean):int");
    }

    public final boolean s0(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return this.a.g.c("debug.firebase.analytics.app", "").equals(str);
    }

    public final int t(String str, boolean z) {
        String[] strArr = v5.a;
        String str2 = GameTrialConstant.NOTIFY_EVENT_KEY;
        if (!m0(str2, str)) {
            return 2;
        }
        if (z) {
            if (!f0(str2, strArr, v5.b, str)) {
                return 13;
            }
        } else if (!f0(str2, strArr, null, str)) {
            return 13;
        }
        if (Z(str2, 40, str)) {
            return 0;
        }
        return 2;
    }

    public final long t0() {
        long nextLong;
        if (this.d.get() == 0) {
            synchronized (this.d) {
                long nanoTime = System.nanoTime();
                Objects.requireNonNull((c) this.a.n);
                nextLong = new Random(nanoTime ^ System.currentTimeMillis()).nextLong();
                int i = this.e + 1;
                this.e = i;
                nextLong += (long) i;
            }
            return nextLong;
        }
        synchronized (this.d) {
            this.d.compareAndSet(-1, 1);
            nextLong = this.d.getAndIncrement();
        }
        return nextLong;
    }

    public final int u0(String str) {
        String str2 = "event param";
        if (!a0(str2, str)) {
            return 3;
        }
        if (!f0(str2, null, null, str)) {
            return 14;
        }
        if (Z(str2, 40, str)) {
            return 0;
        }
        return 3;
    }

    public final SecureRandom v0() {
        g();
        if (this.c == null) {
            this.c = new SecureRandom();
        }
        return this.c;
    }

    public final int w0(String str) {
        String str2 = "event param";
        if (!m0(str2, str)) {
            return 3;
        }
        if (!f0(str2, null, null, str)) {
            return 14;
        }
        if (Z(str2, 40, str)) {
            return 0;
        }
        return 3;
    }

    public final Bundle x(Uri uri) {
        if (uri == null) {
            return null;
        }
        try {
            CharSequence queryParameter;
            CharSequence queryParameter2;
            CharSequence queryParameter3;
            CharSequence queryParameter4;
            String str = "gclid";
            if (uri.isHierarchical()) {
                queryParameter = uri.getQueryParameter("utm_campaign");
                queryParameter2 = uri.getQueryParameter("utm_source");
                queryParameter3 = uri.getQueryParameter("utm_medium");
                queryParameter4 = uri.getQueryParameter(str);
            } else {
                queryParameter = null;
                queryParameter2 = queryParameter;
                queryParameter3 = queryParameter2;
                queryParameter4 = queryParameter3;
            }
            if (TextUtils.isEmpty(queryParameter) && TextUtils.isEmpty(queryParameter2) && TextUtils.isEmpty(queryParameter3) && TextUtils.isEmpty(queryParameter4)) {
                return null;
            }
            Bundle bundle = new Bundle();
            if (!TextUtils.isEmpty(queryParameter)) {
                bundle.putString("campaign", queryParameter);
            }
            if (!TextUtils.isEmpty(queryParameter2)) {
                bundle.putString("source", queryParameter2);
            }
            if (!TextUtils.isEmpty(queryParameter3)) {
                bundle.putString("medium", queryParameter3);
            }
            if (!TextUtils.isEmpty(queryParameter4)) {
                bundle.putString(str, queryParameter4);
            }
            String queryParameter5 = uri.getQueryParameter("utm_term");
            if (!TextUtils.isEmpty(queryParameter5)) {
                bundle.putString("term", queryParameter5);
            }
            queryParameter5 = uri.getQueryParameter("utm_content");
            if (!TextUtils.isEmpty(queryParameter5)) {
                bundle.putString("content", queryParameter5);
            }
            queryParameter5 = "aclid";
            str = uri.getQueryParameter(queryParameter5);
            if (!TextUtils.isEmpty(str)) {
                bundle.putString(queryParameter5, str);
            }
            queryParameter5 = "cp1";
            str = uri.getQueryParameter(queryParameter5);
            if (!TextUtils.isEmpty(str)) {
                bundle.putString(queryParameter5, str);
            }
            queryParameter5 = "anid";
            String queryParameter6 = uri.getQueryParameter(queryParameter5);
            if (!TextUtils.isEmpty(queryParameter6)) {
                bundle.putString(queryParameter5, queryParameter6);
            }
            return bundle;
        } catch (UnsupportedOperationException e) {
            d().i.b("Install referrer url isn't a hierarchical URI", e);
            return null;
        }
    }

    public final Bundle y(Bundle bundle) {
        Bundle bundle2 = new Bundle();
        if (bundle != null) {
            for (String str : bundle.keySet()) {
                Object D = D(str, bundle.get(str));
                if (D == null) {
                    d().k.b("Param value can't be null", j().x(str));
                } else {
                    I(bundle2, str, D);
                }
            }
        }
        return bundle2;
    }

    public final int y0() {
        if (this.f == null) {
            c.e.a.b.b.b bVar = c.e.a.b.b.b.b;
            Context context = this.a.a;
            Objects.requireNonNull(bVar);
            boolean z = e.a;
            int i = 0;
            try {
                i = context.getPackageManager().getPackageInfo("com.google.android.gms", 0);
                i = i.versionCode;
            } catch (NameNotFoundException unused) {
                Log.w("GooglePlayServicesUtil", "Google Play services is missing.");
            }
            this.f = Integer.valueOf(i / 1000);
        }
        return this.f.intValue();
    }

    public final Bundle z(String str, String str2, Bundle bundle, List list, boolean z) {
        t9 t9Var = this;
        String str3 = str2;
        Bundle bundle2 = bundle;
        List list2 = list;
        boolean e0 = e0(str3, v5.d);
        if (bundle2 == null) {
            return null;
        }
        Bundle bundle3 = new Bundle(bundle2);
        int t = t9Var.a.g.t();
        Set treeSet;
        if (t9Var.a.g.u(str, p.Z)) {
            treeSet = new TreeSet(bundle.keySet());
        } else {
            treeSet = bundle.keySet();
        }
        int i = 0;
        for (String str4 : treeSet) {
            int u0;
            int i2;
            String str5;
            if (list2 == null || !list2.contains(str4)) {
                u0 = z ? t9Var.u0(str4) : 0;
                if (u0 == 0) {
                    u0 = t9Var.w0(str4);
                }
            } else {
                u0 = 0;
            }
            if (u0 != 0) {
                F(bundle3, u0, str4, u0 == 3 ? str4 : null);
                bundle3.remove(str4);
                i2 = t;
            } else {
                String str6 = str4;
                i2 = t;
                u0 = s(str, str2, str4, bundle2.get(str4), bundle3, list, z, e0);
                if (u0 == 17) {
                    F(bundle3, u0, str6, Boolean.FALSE);
                } else if (!(u0 == 0 || "_ev".equals(str6))) {
                    F(bundle3, u0, u0 == 21 ? str3 : str6, bundle2.get(str6));
                    bundle3.remove(str6);
                }
                if (X(str6)) {
                    u0 = i + 1;
                    if (u0 > i2) {
                        StringBuilder stringBuilder = new StringBuilder(48);
                        stringBuilder.append("Event can't contain more than ");
                        stringBuilder.append(i2);
                        stringBuilder.append(" params");
                        d().h.c(stringBuilder.toString(), j().u(str3), j().s(bundle2));
                        l0(bundle3, 5);
                        bundle3.remove(str6);
                        str5 = str;
                        i = u0;
                        t = i2;
                        t9Var = this;
                    } else {
                        i = u0;
                    }
                }
            }
            str5 = str;
            t = i2;
            t9Var = this;
        }
        return bundle3;
    }

    public final int z0(String str) {
        if ("_ldl".equals(str)) {
            return 2048;
        }
        if ("_id".equals(str)) {
            return 256;
        }
        return (this.a.g.o(p.h0) && "_lgclid".equals(str)) ? 100 : 36;
    }
}
